<?php
include_once("cron.inc.php");
function get_curl($url, $post = 0, $referer = 0, $cookie = 0, $header = 0, $ua = 0, $nobaody = 0)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    $httpheader[] = "Accept:*/*";
    $httpheader[] = "Accept-Encoding:gzip,deflate,sdch";
    $httpheader[] = "Accept-Language:zh-CN,zh;q=0.8";
    $httpheader[] = "Connection:close";
    curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
    curl_setopt($ch, CURLOPT_TIMEOUT, 5);
    if ($post) {
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    }
    if ($header) {
        curl_setopt($ch, CURLOPT_HEADER, TRUE);
    }
    if ($cookie) {
        curl_setopt($ch, CURLOPT_COOKIE, $cookie);
    }
    if ($referer) {
        if ($referer == 1) {
            curl_setopt($ch, CURLOPT_REFERER, 'http://m.qzone.com/infocenter?g_f=');
        } else {
            curl_setopt($ch, CURLOPT_REFERER, $referer);
        }
    }
    if ($ua) {
        curl_setopt($ch, CURLOPT_USERAGENT, $ua);
    } else {
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Linux; Android 4.4.2; NoxW Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36');
    }
    if ($nobaody) {
        curl_setopt($ch, CURLOPT_NOBODY, 1);
    }
    curl_setopt($ch, CURLOPT_ENCODING, "gzip");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $ret = curl_exec($ch);
    curl_close($ch);
    return $ret;
}

$infoid = 205;
$list = $pdo->query("select * from `zy_qqs` where `cookiezt`=1 limit 3");
$row = $list->fetch();
if ($row != false) {
	$uin = $row['qq'];
    $pwd = authcode($row['pwd'], 'DECODE', WEB_KEY);
	$api = $configs['is_qqlogin_api_url_'.$row['area']];
	$check=json_decode(get_curl($api.'?do=checkvc',['uin'=>$uin,'tokenid'=>null]),true);
	if($check['saveOK']==0){ //不需要验证码
		$vcode=$check['vcode'];
		$pt_verifysession=$check['pt_verifysession'];
	}else{
		$getvc_data=[
			'uin'	=>	$row['qq'],
			'sig'	=>	$check['sig'],
			'sess'	=>	0,
			'sid'	=>	null,
			'websig'	=>	null
		];
		$array=json_decode(get_curl($api.'?do=getvc',$getvc_data),true);
		if($array['saveOK']==2){//滑动验证码
			$dovc_data=[
				'uin'	=>	$row['qq'],
				'sig'	=>	$check['sig'],
				'ans'	=>	$array['ans'],
				'cap_cd'	=>	$check['sig'],
				'sess'	=>	$array['sess'],
				'collectname'	=>	$array['collectname'],
				'websig'	=>	$array['websig'],
				'cdata'	=>	$array['cdata'],
				'sid'	=>	$array['sid']
			];
			$array=json_decode(get_curl($api.'?do=dovc',$dovc_data),true);//提交验证码
			if($array['rcode']==0){
				$vcode=$array['randstr'];
				$pt_verifysession=$array['sig'];
			}else{
				$myrow = $pdo->query("SELECT * FROM zy_users WHERE uid='{$row['uid']}' limit 1")->fetch();
				$pdo->exec("UPDATE zy_qqjob SET lasttime='$date2' WHERE qid='" . $row['qid'] . "' and type='auto'");
				echo $row['qq'].' 验证失败<br/>';
			}
		}else{
			$myrow = $pdo->query("SELECT * FROM zy_users WHERE uid='{$row['uid']}' limit 1")->fetch();
			$pdo->exec("UPDATE zy_qqjob SET lasttime='$date2' WHERE qid='" . $row['qid'] . "' and type='auto'");
			echo $row['qq'].' 需要验证码<br/>';
		}
	}
	if(isset($vcode)){
		$p=get_curl('http://encode.qqzzz.net/?type=1&uin='.$row['qq'].'&pwd='.strtoupper(md5($row['pwd'])).'&vcode='.strtoupper($vcode));
		if($p=='error'||$p=='')exit($row['qq'].' getp failed!<br/>');
		$arr=json_decode(get_curl($api.'?do=qqlogin',['uin'=>$uin,'pwd'=>$pwd,'p'=>$p,'vcode'=>$vcode,'pt_verifysession'=>$pt_verifysession,'cookie'=>$check['cookie']]));
		if(is_array($arr)&&$arr['saveOK']==0){
			$sid = $arr['sid'];
            $skey = $arr['skey'];
            $pskey = $arr['pskey'];
            $superkey = $arr['superkey'];
            $pdo->exec("UPDATE zy_qqs SET sid='{$sid}',skey='{$skey}',pskey='{$pskey}',superkey='{$superkey}',cookiezt='0',`time`='{$date2}' WHERE qid='" . $row['qid'] . "'");
            $pdo->exec("UPDATE zy_qqjob SET lasttime='$date2' WHERE qid='" . $row['qid'] . "' and type='auto'");
			echo $row['qq'].' 更新成功!<br/>';
		}elseif($arr['saveOK']==3){
			$myrow = $pdo->query("SELECT * FROM zy_users WHERE uid='{$row['uid']}' limit 1")->fetch();
            $pdo->exec("UPDATE zy_qqjob SET lasttime='$date2' WHERE qid='" . $row['qid'] . "' and type='auto'");
			echo $row['qq'].' 密码错误<br/>';
		}else{
			$myrow = $pdo->query("SELECT * FROM zy_users WHERE uid='{$row['uid']}' limit 1")->fetch();
			$pdo->exec("UPDATE zy_qqjob SET lasttime='$date2' WHERE qid='" . $row['qid'] . "' and type='auto'");
			echo $row['qq'].' 登陆失败<br/>';
		}
		unset($vcode);unset($pt_verifysession);
	}
    unset($vcode);
    unset($pt_verifysession);
}
$pdo->exec("update `zy_info` set `last`='{$date}' where sysid='{$infoid}'");
$pdo->exec("update `zy_info` set `times`=`times`+1,`last`='{$date}' where sysid='0'");
$pdo = null;
echo '执行时间: '.$date;

